package com.hn.shirojwt.controller;


import com.hn.shirojwt.entity.User;
import com.hn.shirojwt.util.JwtTokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/")
public class TestController {

    JwtTokenUtil jwtTokenUtil = new JwtTokenUtil();

    @GetMapping("/hello")
    public String hello() {
        return "hello word";
    }

    @GetMapping("/login")
    public String login(String username, String password) {
        User user = null;
        if ("admin".equals(username)){
            user = new User().setUsername(username).setRole("admin");
        }else if("user".equals(username)){
            user = new User().setUsername(username).setRole("user");
        }else {
            user = new User().setUsername(username).setRole("other");
        }
        String token = jwtTokenUtil.generateToken(user);
        return token;
    }

    @GetMapping("/admin")
    public String admin(){
        return "hello admin";
    }

    @GetMapping("/user")
    public String user(){
        return "hello userOrAdmin";
    }

}
